package com.java01.misc.bitwise;

public class Bitwise1 {

	public static final int MESSAGE_IS_SIGNED       = 1 << 0;
    public static final int MESSAGE_IS_ENCRIPTED    = 1 << 1;
    public static final int MESSAGE_HAS_ATTACHMENT  = 1 << 2;
    public static final int MESSAGE_HAS_BEEN_READ   = 1 << 3;
    public static final int MESSAGE_IS_SPAM         = 1 << 4;
    
    private int message_flag = 0; 
    
    public void set(int flags){
    	message_flag |= flags;
    }
    
    public boolean is(int flags){
    	return (message_flag & flags)==flags;
    }
    
	public static void main(String[] args) {

		Bitwise1 message = new Bitwise1();
		message.set(MESSAGE_HAS_ATTACHMENT|MESSAGE_HAS_BEEN_READ|MESSAGE_IS_SPAM);
		
		System.out.println(message.is(MESSAGE_IS_SPAM)?"yes":"no");
		System.out.println(message.is(MESSAGE_IS_SPAM|MESSAGE_IS_SIGNED)?"yes":"no");
		System.out.println(message.is(MESSAGE_HAS_ATTACHMENT|MESSAGE_HAS_BEEN_READ)?"yes":"no");
	}

}
